home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / RESEDIT_ / ICON_PIC / ICON_PIC.C
Text File  |  1991-10-16  |  6KB  |  182 lines

  1. /******************************************************************************
  2.  COPYRIGHT (C) 1984-1990 Apple Computer,Inc.
  3.  All rights reserved
  4.  Icon Resource Picker
  5.     Modifications for THINK C by Maarten Meijer, 1991
  6.  
  7.     
  8.     Some modifications by Erik A. Johnson (johnsone@uxh.cso.uiuc.edu) for
  9.     THINK C (5.0.1).
  10.  
  11. *******************************************************************************/
  12. /*    This is the Icon resource picker example.
  13.     The general scheme is that a List structure is created whose cells
  14.     contain the ID's of this resource type.  A drawproc is installed in the List
  15.     record which is called to display the resource. */
  16.  
  17. #ifdef THINK_C
  18. #if THINK_C == 5
  19. /* these following are included in the THINK C precompiled MacHeaders file */
  20. /*#include <Types.h>*/
  21. /*#include <Menus.h>*/
  22. /*#include <Resources.h>*/
  23. /*#include <Memory.h>*/
  24. /*#include <Lists.h>*/
  25. #else
  26. /* these following are included in the THINK C precompiled MacHeaders file */
  27. /*#include <MacTypes.h>*/
  28. /*#include <MenuMgr.h>*/
  29. /*#include <ResourceMgr.h>*/
  30. /*#include <MemoryMgr.h>*/
  31. /*#include <ListMgr.h>*/
  32. #endif
  33. #else
  34. #include    <types.h>
  35. #include    <memory.h>
  36. #include    <menus.h>
  37. #include    <resources.h>
  38. #include    <lists.h>
  39. #endif
  40.  
  41. #include    "ResEd.h"
  42.  
  43. #define iconMenuID 10            /* Just one of ResEdit's menus. */
  44. #define listCellSizeH             0x38
  45. #define listCellSizeV                0x42
  46.     
  47. /* Needs to be 2 wide so that I can always tell a 2 dimensional list from a normal text list. */
  48. #define minIconsPerRow             2
  49. #define ICONMinWindowWidth     (minIconsPerRow * listCellSizeH) + theScrollBar
  50. #define ICONMinWindowHeight listCellSizeV
  51.  
  52.  
  53.     typedef struct IconPickRec {
  54.         ParentHandle        father;                /* Back ptr to dad             */
  55.         Str255                fName;                /* Max 255 characters.         */         
  56.         WindowPtr            wind;                /* Picker window         */
  57.         Boolean                rebuild;            /* Flag set to indicate that window should be rebuilt  */
  58.         Boolean                spare1;                /* Not used here */
  59.         unsigned char        windowType;
  60.         ResType                theResType;            /* Type of the resource being picked or edited. */
  61.         short                theResFile;            /* The home resfile of the window. */
  62.         short                codeResID;            /* Resource ID of the RSSC resource containing the picker or editor. */
  63.         Handle                spare;                /* Not used here */
  64.  
  65.         ResType                rType;                /* Type for this picker     */
  66.         long                rSize;                /* size of a null resource     */
  67.         short                minWindowWidth;        /* Use when the window is grown. */
  68.         short                minWindowHeight;
  69.         ListHandle            instances;            /* List of instances         */
  70.         short                nInsts;                /* Number of instances         */
  71.         unsigned char        viewBy;                /* Current view type        */
  72.         Boolean                showAttributes;        /* Show attrs in window?    */
  73.         ResType                ldefType;            /* Which LDEF to use        */
  74.         MenuHandle            theViewMenu;        /* The picker view menu        */
  75.         long                viewMenuMask;        /* Which items are enabled?    */
  76.         Cell                cellSize;            /* Size for special view.    */
  77.         MenuHandle            iconMenu;            /* Our menu */
  78.     } IconPickRec;
  79.     
  80.     typedef    IconPickRec    *IconPickPtr;
  81.     typedef    IconPickPtr    *IconPickHandle;
  82.  
  83. #ifdef THINK_C
  84. #pragma mark _prototypes
  85. pascal void EditBirth(Handle thing, ParentHandle dad);
  86. pascal void PickBirth(ResType t, ParentHandle dad);
  87. pascal void DoEvent(EventRecord *evt, IconPickHandle pick);
  88. pascal void DoInfoUpdate(short oldID, short newID, PickHandle pick);
  89. pascal void DoMenu(short menu, short item, IconPickHandle pick);
  90. pascal Boolean IsThisYours (Handle thing, PickHandle pick);
  91. pascal short ResEdID(void);
  92. #endif
  93.  
  94. /* Used only for editors. */
  95. pascal void EditBirth(Handle thing, ParentHandle dad)
  96. {SysBeep(20);
  97.     #pragma    unused (thing, dad)
  98. }
  99.  
  100. /* *********************************************************************************** */
  101.  
  102. pascal void PickBirth(ResType t, ParentHandle dad)
  103. {
  104.     IconPickHandle     pick;
  105.     IconPickPtr            p;                    /* temp ptr for *pick */
  106.     MenuHandle            theIconMenu;
  107.     
  108.     SysBeep(20);
  109.     pick = (IconPickHandle)NewHandle(sizeof(IconPickRec));
  110.     SysBeep(20);
  111.  
  112.     p = *pick;
  113.  
  114.     p->father = dad;                         /* Back ptr to dad                                                                             */
  115.     p->rType = t;                             /* Resource type that I understand                                             */
  116.     p->viewBy = viewBySpecial;                /* Special means we have our own LDEF to draw the icons */
  117.     p->ldefType = t;                        /* Which LDEF do we use? */
  118.     p->cellSize.h = listCellSizeH;            /* Set the size of the cell.                                                        */
  119.     p->cellSize.v = listCellSizeV;
  120.     p->minWindowWidth = ICONMinWindowWidth;
  121.     p->minWindowHeight = ICONMinWindowHeight;
  122.     
  123.     SysBeep(20);
  124.     /* Setup the list and create the window. */
  125.     if (!DoPickBirth(noColor, true, graphical2DPicker, ResEdID(), (PickHandle)pick))
  126.         DisposHandle ((Handle)pick);        /* Error */
  127.     else {
  128.         theIconMenu = GetMenu(iconMenuID);
  129.         DetachResource((Handle)theIconMenu); /* Get our own copy of the menu. */
  130.         (*pick)->iconMenu = theIconMenu;
  131.         }
  132. }
  133. /* *********************************************************************************** */
  134.  
  135. /* Everything is taken care of for us by PickEvent. */
  136. pascal void DoEvent(EventRecord *evt, IconPickHandle pick)
  137. {
  138.     PickEvent(evt, (PickHandle)pick);
  139.     if (evt->what == activateEvt) {
  140.         if (evt->modifiers & activeFlag)
  141.             InsertMenu((*pick)->iconMenu, 0);
  142.         else
  143.             DeleteMenu(iconMenuID);
  144.         DrawMBarLater(false);
  145.         }
  146. }
  147.  
  148. /* *********************************************************************************** */
  149.  
  150. /* Everything is taken care of for us by PickInfoUp                                                                      */
  151. pascal void DoInfoUpdate(short oldID, short newID, PickHandle pick)
  152. {
  153.     PickInfoUp(oldID, newID, pick);
  154. }
  155.  
  156. /* *********************************************************************************** */
  157.  
  158. pascal Boolean IsThisYours (Handle thing, PickHandle pick)
  159.  
  160. {
  161.     #pragma    unused (thing, pick)
  162.     return false;
  163. }
  164.  
  165. /* *********************************************************************************** */
  166.  
  167. /* Everything is taken care of for us by PickMenu.                                                                        */
  168. pascal void DoMenu(short menu, short item, IconPickHandle pick)
  169. {
  170.     if (menu == iconMenuID) {
  171.         /* Do something with the menu */
  172.         }
  173.     else {
  174.         if ((menu == fileMenu) && (item == closeItem)) {
  175.             DeleteMenu(iconMenuID);
  176.             DrawMBarLater(false);
  177.             DisposHandle((Handle)(*pick)->iconMenu);
  178.             }
  179.         PickMenu(menu, item, (PickHandle)pick);
  180.         }
  181. }
  182.